import SparkMD5 from "spark-md5";

export function createChunk(file:any,index:any,chunkSize:any){
    return new Promise((resolve)=>{
        const start = index * chunkSize;
        const end = start + chunkSize;
        const spark = new SparkMD5.ArrayBuffer();
        const fileReader = new FileReader();
        fileReader.onload = (e:any)=>{
            spark.append(e.target?.result);        
            resolve({
                start,
                end,
                index,
                hash : spark.end(),
                chunkData: file.slice(start,end), 
            })
        };
        fileReader.readAsArrayBuffer(file.slice(start,end))
        
    })
}